package troqler;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.model.SelectItem;
import javax.inject.Inject;
import javax.inject.Named;
import javax.sql.DataSource;

@Named
@ApplicationScoped
public class KategoriFinner implements Serializable{
    private ArrayList<String> kats = new ArrayList<String>();
    @Inject
    private LocaleBean locale;
    @Resource(name="jdbc/waplj_prosjekt")
    private DataSource ds;
    
    public KategoriFinner()
    {
       
    }
    @PostConstruct
    public void postConstruct() throws SQLException
    {
        Connection con = ds.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT kategorinavn FROM kategori");
        if(ps.execute())
        {
            ResultSet res = ps.getResultSet();
            while(res.next())
            {
                kats.add(res.getString("kategorinavn"));
            }
            res.close();
        }
        ps.close();
        con.close();
    }

    public List<String> getKategorier()
    {
        return kats;
    }
    
}
